package com.pug.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pug.domain.KssOrder;
import com.pug.domain.KssUser;
import com.pug.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @author panghu
 * @version 1.0.0
 * @createTime 2022年08月12日 23:49:00
 * @Description
 */
@Service
@Slf4j
public class OrderServiceImpl extends ServiceImpl<OrderMapper, KssOrder> implements OrderService{

    @DubboReference(check = false) // 从注册中心中获取实现类
    private UserService userService;

    /**
     * 根据用户id查询订单信息
     * @param userId
     * @return
     */
    @Override
    public KssOrder getOrderInfo(Long userId) {
        LambdaQueryWrapper<KssOrder> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(KssOrder::getUserId,userId);
        KssOrder kssOrder = this.getOne(lambdaQueryWrapper);

        // 远程调用- 用户服务
        KssUser user = userService.getUserById(userId);
        kssOrder.setKssUser(user);

        return kssOrder;
    }
}
